package cxydmmszl.chapter05.t080;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <li style="color: red;">Prob</li>
 * 字符串的统计字符串
 * <li style="color: green;">Desc</li>
 * 给定一个字符串str，返回str的统计字符串。例如“aaabbbbcccd”的统计字符串为“a_3_b_4_c_3_d_1”。
 * <li style="color: green;">Input</li>
 * 输入一行字符串，代表str 1≤length（str）≤10^5
 * <li style="color: green;">Output</li>
 * 输出一行字符串，代表统计字符串。
 * <li style="color: blue;">Link</li> CD98
 *
 * @author habitplus
 * @since 2021-09-08 14:42
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String s = bf.readLine();
        bf.close();
        s = toCntStr(s);
        System.out.println(s);
    }

    private static String toCntStr(String s) {
        if (s == null || s.length() == 0) {
            return "";
        }

        char[] chs = s.toCharArray();
        int n = chs.length;
        int num = 1;
        StringBuilder res = new StringBuilder();
        res.append(chs[0]);
        for (int i = 1; i < n; i++) {
            if (chs[i-1] == chs[i]) {
                num++;
            } else {
                res.append('_').append(num).append('_').append(chs[i]);
                num = 1;
            }
        }
        res.append('_').append(num);
        return res.toString();
    }
}
